package com.company.cloud.club.modules.db.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.cloud.club.modules.db.domain.ProductInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ProductInfoMapper extends BaseMapper<ProductInfo> {

    @Select("SELECT * FROM prd_product_info WHERE product_no = #{productNo, jdbcType=VARCHAR}")
    ProductInfo findByProductNo(@Param("productNo") String productNo);

    @Select("SELECT * FROM prd_product_info ORDER BY cdt DESC limit #{pageStart}, #{pageEnd}")
    List<ProductInfo> pageByRecent(@Param("pageStart") Integer pageStart,
                                  @Param("pageEnd") Integer pageEnd);

    @Select("SELECT count(*) FROM prd_product_info")
    Integer countByRecent();

    @Select("SELECT * FROM prd_product_info WHERE biz_value4 = #{artistNo, jdbcType=VARCHAR} AND DATE_SUB(CURDATE(), INTERVAL 3 DAY) <= date(cdt) ORDER BY cdt DESC")
    List<ProductInfo> selectLast3Days(@Param("artistNo") String artistNo);

    @Select("SELECT * FROM prd_product_info WHERE biz_value4 = #{artistNo, jdbcType=VARCHAR} AND DATE_SUB(CURDATE(), INTERVAL 3 DAY) > date(cdt) ORDER BY cdt DESC")
    List<ProductInfo> selectDaysAgo(@Param("artistNo") String artistNo);

    @Select("SELECT count(*) FROM prd_product_info WHERE biz_value4 = #{artistNo, jdbcType=VARCHAR}")
    Integer countArtistProductNum(@Param("artistNo")  String artistNo);

}